<template>
  <c-dialog ref="dialog" :open-fun="openFun" title="审核">
    <c-list ref="form" :column="1" :model="formData" :rules="formRules" label-width="80px">
      <c-list-item label="验收任务号" :value="detail.acceptTaskCode" />
      <c-list-item label="所属门店" :value="detail.shopName" />
      <c-list-item label="验收类型" :value="detail.acceptType" dict-type-code="ACCEPT_TYPE" />
      <c-list-item prop="acceptApplyReviewResult" label="审核结果">
        <el-select v-model="formData.acceptApplyReviewResult" placeholder="审核结果" style="width:100%" clearable>
          <el-option label="同意" :value="1" />
          <el-option label="不同意" :value="0" />
        </el-select>
      </c-list-item>
      <c-list-item :rules="[{ required: !formData.acceptApplyReviewResult, message: '请输入审核意见', trigger: 'change' }]" prop="acceptApplyReviewAdvice" label="审核意见">
        <el-input v-model="formData.acceptApplyReviewAdvice" type="textarea" placeholder="审核意见" maxlength="1024" show-word-limit :autosize="{minRows:3}" clearable />
      </c-list-item>
      <c-list-item>
        <div class="btn-container">
          <c-button @click="clickCancelHandle">取消</c-button>
          <c-button type="primary" @click="clickConfirmHandle">确认</c-button>
        </div>
      </c-list-item>
    </c-list>
  </c-dialog>
</template>
<script>
import { postShopAccept, getAuditCheck } from '@/api/check'
export default {
  name: 'Audit',
  props: {
    selData: {
      type: Array,
      default: () => []
    },
    type: {
      type: String,
      default: 'HARD'
    }
  },
  data() {
    return {
      formData: {
        acceptApplyReviewResult: '',
        acceptApplyReviewAdvice: ''
      },
      formRules: {
        acceptApplyReviewResult: [{ required: true, message: '请选择审核结果', trigger: 'change' }]
        // acceptApplyReviewAdvice: [{ required: true, message: '请输入审核意见', trigger: 'change' }]
      }
    }
  },
  computed: {
    detail() {
      return this.selData.length > 0 ? this.selData[0] : {}
    }
  },
  methods: {
    clickConfirmHandle() {
      return this.$refs.form.validate().then(() => {
        const data = {
          ...this.formData,
          id: this.detail.id
        }
        return postShopAccept(data).then(res => {
          this.$message.success('操作成功！')
          this.$emit('on-success')
          this.$refs.dialog.visible = false
        })
      })
    },
    clickCancelHandle() {
      this.$refs.dialog.visible = false
    },
    openFun() {
      if (!this.singleJudge(this.selData, '审核', true)) {
        return false
      }
      if (this.type === 'SOFT') {
        return getAuditCheck(this.selData[0].id)
      }
      return true
    }
  }
}
</script>
